package day06;

import java.util.Arrays;

public class Test {
    private int id;
    private String name;
    private  int age;
    private  Emp[] emps;

    public Test(int id, String name, int age, Emp[] emps) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.emps = emps;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Emp[] getEmps() {
        return emps;
    }

    public void setEmps(Emp[] emps) {
        this.emps = emps;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("Test{");
        sb.append("id=").append(id);
        sb.append(", name='").append(name).append('\'');
        sb.append(", age=").append(age);
        sb.append(", emps=").append(emps == null ? "null" : Arrays.asList(emps).toString());
        sb.append('}');
        return sb.toString();
    }

    public Test() {
    }
    public  void addEmp(Emp e){
        if(null==emps){
            System.out.println("抱歉，没有权限");
            return;

        }
        emps=Arrays.copyOf(emps,emps.length+1);
        emps[emps.length-1]=e;
        System.out.println("有权限");


    }
    public  void  delById(int id){
        if (null==emps || emps.length==0){
            System.out.println("shanchushibai");
        return;
        }
        Emp[] temp=new Emp[emps.length-1];
        int pos=0;
        for (int i = 0; i <emps.length ; i++) {
            if (emps[i].getId()==id){
                temp[pos++]=emps[i];

            }

        }
        emps=temp;
    }
}
